<template>
	<view class="code-box">
		<uni-nav-bar-vue title="" :dark="true" themeBgColor="#1F2130" leftIcon="left" themeColor="#fff"
			@clickLeft="clickLeft"></uni-nav-bar-vue>
		<view class="container">
			<view class="box">
				<view class="logo">
					<image :src="userInfo.avatar" class="logo-img"></image>
				</view>
				<view class="sy-box">
					<image :show-menu-by-longpress="true" :src="codeImg" class="code-img"></image>
					<view class="text">推广数字码</view>
					<view class="num">{{userInfo.id}}</view>
				</view>
				<image src="https://fuqiaohui.oss-cn-chengdu.aliyuncs.com/merchant/dot.png" class="dot"></image>
				<image src="https://fuqiaohui.oss-cn-chengdu.aliyuncs.com/merchant/scan.png" class="scan"></image>
				<view class="cs">会员扫码或输入推广数字码购买会员后获得佣金</view>
				<view class="cx">长按二维码保存为图片</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCode,
		getUserInfo
	} from '../../api/active.js'
	import uniNavBarVue from "../../uni_modules/uni-nav-bar/components/uni-nav-bar/uni-nav-bar.vue"
	export default {
		components: {
			uniNavBarVue
		},
		data() {
			return {
				codeImg: '',
				userInfo: ''
			}
		},
		onLoad() {
			getUserInfo({
				userId: uni.getStorageSync("userId")
			}).then(res => {
				this.userInfo = res.data
			})
			this.getCodeImg()
		},
		methods: {
			clickLeft() {
				uni.navigateBack()
			},
			getCodeImg() {
				uni.request({
					url: "https://www.bcwd.cc/fq-server/openapi-service/createMinQrCode",
					method: 'POST',
					data: {
						path: 'pages/vip/vip',
						data: 'id=' + uni.getStorageSync("userId"),
						appid: "wxd7029c6a261ef094",
						width: 1280
					},
					header: {
						Authorization: "accessToken " + uni.getStorageSync("token")
					}, //请求头
					responseType: 'arraybuffer', //告诉服务器你希望得到的响应类型为arraybuffer（二进制数据）类型
					success: res => {
						console.log(res)
						//微信小程序不支持btoa，所以可以用下面这个
						this.codeImg = 'data:image/png;base64,' + uni.arrayBufferToBase64(res.data);
					},
				});

				// getCode({
				// 	path: 'pages/vip/vip',
				// 	data: 'id=' + uni.getStorageSync("userId"),
				// 	appid: "wxd7029c6a261ef094"
				// }).then(res => {
				// 	this.codeImg = 'data:image/png;base64,' + uni.arrayBufferToBase64(res.data);
				// })
			}
		}
	}
</script>

<style lang="scss" scoped>
	.code-box {
		width: 100vw;
		height: 100vh;
		overflow: hidden;
		background: linear-gradient(180deg, #005097, #b4c9dc);
		overflow: hidden;
		display: flex;
		flex-direction: column;
	}
	.container {
		width: 100vw;
		padding-top: 115rpx;
		padding-bottom: 20rpx;
		display: flex;
		justify-content: center;
	}

	.box {
		width: 702rpx;
		// height: 1262rpx;
		padding-bottom: 30rpx;
		background: #ffffff;
		border-radius: 20rpx;
		text-align: center;
	}

	.logo {
		width: 187rpx;
		height: 187rpx;
		background: #ffffff;
		border-radius: 50%;
		margin-left: 254rpx;
		margin-top: -93rpx;
		position: relative;

		.logo-img {
			width: 100%;
			height: 100%;
			border-radius: 50%;
		}
	}

	.sy-box {
		height: 725rpx;
	}

	.code-img {
		display: block;
		width: 540rpx;
		height: 540rpx;
		margin: 10rpx auto 0 auto;
	}

	.text {
		font-weight: 500;
		font-size: 28rpx;
		color: #999999;
		margin-top: 20rpx;
	}

	.num {
		font-family: DIN;
		font-weight: bold;
		font-size: 97rpx;
		color: #333333;
	}

	.dot {
		width: 601rpx;
		height: 6rpx;
	}

	.scan {
		width: 46rpx;
		height: 47rpx;
		margin: 25rpx auto 0 auto;
		display: block;
	}

	.cs {
		font-weight: 500;
		font-size: 28rpx;
		color: #333333;
		margin-top: 20rpx;
	}

	.cx {
		font-weight: 500;
		font-size: 24rpx;
		color: #999999;
		margin-top: 18rpx;
	}

	.use {
		width: 347rpx;
		height: 347rpx;
		margin-top: 79rpx;
	}

	.ts {
		font-weight: 500;
		font-size: 34rpx;
		color: #999999;
		margin-top: 76rpx;
		line-height: 1.8;
	}
</style>